package com.example.assign2_list;

import java.text.DateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.TextView;

public class AlarmClock extends Activity {
	private Handler handle = new Handler();
	private TextView clock;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_clock);
        
        clock  = (TextView) findViewById(R.id.clockView);
        Thread thr = new Thread(null, sleep, "ClockThread");
        thr.start();
    }
    Runnable sleep = new Runnable(){
    	public void run(){
    		while(true){
    			handle.post(update);	// Update clock every 5 second
    			SystemClock.sleep(5000);
    		}
    	}
    };
    Runnable update = new Runnable(){
    	public void run(){
            Date date = new Date(System.currentTimeMillis());		//	Get System time
            String time = DateFormat.getTimeInstance().format(date);	//	set normal format
            clock.setText(time);
    	}
    };
    
    /*	onClick Set Alarm button	*/
	public void setAlarmsButton(View v){
		Intent setAlarms = new Intent (this, SetAlarms.class);
		startActivity(setAlarms);
	}
}
